<template>
  <van-nav-bar
    :left-arrow="leftArrow"
    :title="title"
    :left-text="leftText"
    :border="border"
    :color="color"
    @click-left="onClickLeft"
  >
    <template #right>
      <van-icon name="search" size="20" color="#FFFFFF" @click="searchKwds"/>
      <van-icon class="plus" name="plus" size="20" color="#FFFFFF" @click="addUser()"/>
    </template>
  </van-nav-bar>
</template>

<script>
import Header from './LeftArrowHeader'

export default {
  name: 'LeftArrowHeader',
  components: {
    Header
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    leftText: {
      type: String,
      default: ''
    },
    leftArrow: {
      type: Boolean,
      default: false
    },
    search: {
      type: Boolean,
      default: undefined
    },
    border: {
      type: Boolean,
      default: true
    },
    color: {
      type: String,
      default: undefined
    },
    isShowTag: {
      type: Boolean,
      default: true
    },
    roles: {
      type: String,
      required: true
    }
  },
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    searchKwds() {
      this.$emit('search', true)
    },
    addUser() {
      let path = ''
      let title = ''
      const isShowTag = this.isShowTag
      if (this.roles === 'addUser') {
        path = '/addUser'
        title = '添加用户'
      } else if (this.roles === 'addCourse') {
        path = '/addCourse'
        title = '添加课程'
      }
      this.$router.push({
        path,
        query: { title, isShowTag }
      })
    }
  }
}
</script>

<style scoped lang="less" rel="stylesheet/less">
.plus {
  margin-left: 20px;
}
</style>
